jQuery(document).ready(function($) {
			var interval = 0;
			var bar = jQuery('.main').progressbutton();
			jQuery('#reset').click(function() {
				clearInterval(interval);
				if (bar) {
					bar.progressbutton('reset');
				}
			});
			jQuery('.color').click(function() {
				//clearInterval(interval);
				var clicked = jQuery(this);
				bar.progressbutton({
					color: clicked.data('color')
				});
			});
			jQuery('.opacity').click(function() {
				//clearInterval(interval);
				var clicked = jQuery(this);
				bar.progressbutton({
					opacity: clicked.data('opacity')
				});
			});

			jQuery('.test').click(function() {
				var itm = jQuery(this);
				if (itm.hasClass('disable')) {
					itm.attr('disabled', 'disabled');
				}
				var bar = itm.progressbutton({
					percent: -1
				});
				var clock = 0;

				var interval = setInterval(function() {
					bar.progressbutton({
						percent: clock
					});
					clock = clock + 0.5;
					if (clock > 100) {
						itm.removeAttr('disabled');
						clearInterval(interval);
						bar.progressbutton('reset');
					}
				}, 30);
			});
			jQuery('.action').click(function() {
				clearInterval(interval);
				var clicked = jQuery(this);
				bar.progressbutton({
					percent: clicked.data('percent')
				});
			});
			jQuery('.other').click(function() {
				var itm = jQuery('#standard');
				var bar = itm.progressbutton({
					percent: -1
				});
				var clock = 0;

				var interval = setInterval(function() {
					bar.progressbutton({
						percent: clock
					});
					clock = clock + 0.5;
					if (clock > 100) {
						clearInterval(interval);
						bar.progressbutton('reset');
					}
				}, 30);
			});


		});
		
		// Bind normal buttons
		Ladda.bind('.button-demo button', {
			timeout: 2000
		});

		// Bind progress buttons and simulate loading progress
		Ladda.bind('.progress-demo button', {
			callback: function(instance) {
				var progress = 0;
				var interval = 0;
				interval = setInterval(function() {
					progress = Math.min(progress + Math.random() * 0.1, 1);
					instance.setProgress(progress);

					if (progress === 1) {
						instance.stop();
						clearInterval(interval);
					}
				}, 200);
			}
		});	